#include <iostream>
#include <stdlib.h>

#include "gtest/gtest.h"

const size_t cvt_test_d_len = 500 * 1024;
static uint16_t * u16buf = new uint16_t[2 * cvt_test_d_len];
static float * f32buf = new float[4 * cvt_test_d_len];
TEST(Cvt, U16toF32){
    for (int j = 0; j < 100; ++j) {
        size_t size = cvt_test_d_len;
        for (size_t i = 0; i < size; ++i) {
            f32buf[i] = u16buf[i];
        }
    }
}

TEST(Cvt, U32toF16){
    for (int j = 0; j < 100; ++j) {
        size_t size = cvt_test_d_len;
        for (size_t i = 0; i < size; ++i) {
            u16buf[i] = static_cast<uint16_t>(f32buf[i]);
        }
    }
}


TEST(Cvt, F32C4toU8C4){
    for (int j = 0; j < 100; ++j) {
        uint32_t * u8c4buf = reinterpret_cast<decltype (u8c4buf)>(u16buf);
        size_t size = cvt_test_d_len;
        for (size_t i = 0; i < size; ++i) {
            auto idx = i * 4;
            uint32_t t;
            t = static_cast<uint8_t>(f32buf[idx]);
            idx++;
            t += (static_cast<uint8_t>(f32buf[idx]) << 8);
            idx++;
            t += (static_cast<uint8_t>(f32buf[idx]) << 8);
            idx++;
            t += (static_cast<uint8_t>(f32buf[idx]) << 8);
            u8c4buf[i] = t;
        }
    }
}

TEST(MemCpy, Uint32ToUint32){
    auto dst = std::shared_ptr<uint32_t>(new uint32_t[512 * 500]);
    auto src = std::shared_ptr<uint32_t>(new uint32_t[512 * 500]);
    for (int i = 0; i < 100; ++i) {
        std::memcpy(dst.get(), src.get(), 512*500*4);
    }
}

GTEST_API_ int main(int argc, char **argv) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
